package com.cskaoyan.controller;

import com.cskaoyan.bean.data.CollectListData;
import com.cskaoyan.bean.data.PageData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CollectAddOrDeleteVo;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    CollectService collectService;

    //--->type=0&page=1&limit=10
    @GetMapping("list")
    public BaseRespVo list(Byte type, Integer page, Integer limit) {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            Integer userId = (Integer) subject.getPrincipal();
            PageData data = collectService.selectAll(userId, type, page, limit);
            return BaseRespVo.ok(data);
        }
        return BaseRespVo.unAuthc();
    }

    //--->{"type":?,"valueId":?}
    @PostMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody CollectAddOrDeleteVo collectAddOrDeleteVo) {
        Integer result = collectService.addOrDeleteCollect(collectAddOrDeleteVo);
        // 1 --->成功
        if (result == 1) {
            return BaseRespVo.ok(null);
        }
        //-1 --->未登录
        return BaseRespVo.unAuthc();
    }
}
